#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
void Swap(int* p1, int* p2)
{
	int temp = *p1;
	*p1 = *p2;
	*p2 = temp;
}
void SelectSort(int* arr, int len)
{
	int begin = 0; int end = len - 1;
	while (begin < end)
	{
		int mini = begin;
		int maxi = end;
		for (int i = begin; i <= end; i++)
		{
			if (arr[i] < arr[mini])
				mini = i;
			if (arr[i]>arr[maxi])
				maxi = i;
		}
		Swap(&arr[mini], &arr[begin]);
		if (maxi == begin)
			maxi = mini;
		Swap(&arr[maxi], &arr[end]);
		begin++;
		end--;
	}
}
int main()
{
	int arr[] = { 9, 8, 7, 6, 5, 4, 3, 2, 1 };
	int len = sizeof(arr) / sizeof(arr[0]);
	SelectSort(arr, len);
	for (int i = 0; i < len; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
	return 0;
}